package com.course.controller;

import com.course.entity.ResultBody;
import com.course.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/Login")
@CrossOrigin(origins="*")
public class LoginController {
    @Autowired
    private LoginService loginService;
    @RequestMapping("/LoginUser")
    //学生老师端注册模块
    public ResultBody LoginUser(@RequestBody Map<String,Object> map) {
        //检验参数是否完整
        if(map.get("userstyle")==null||map.get("usernumber")==null || map.get("userpassword")==null)
        {
            return new ResultBody(404,"参数错误",false);
        }
        String userstyle= map.get("userstyle").toString();
        String usernumber = map.get("usernumber").toString();
        String userpassword = map.get("userpassword").toString();
        //将信息进行传入
        return loginService.loginuser(userstyle,usernumber,userpassword);
    }
    @RequestMapping("/Loginadmin")
    public ResultBody loginadmin(@RequestBody Map<String,Object> map) {
        if(map.get("phone")==null || map.get("password")==null)
        {
            return new ResultBody(404,"参数错误",false);
        }
        return loginService.loginadmin(map);
    }
}
